package com.david.func_test.worker

import android.content.Context
import android.util.Log
import android.widget.Toast
import androidx.work.OneTimeWorkRequestBuilder
import androidx.work.WorkManager
import androidx.work.Worker
import androidx.work.WorkerParameters
import java.util.*
import java.util.concurrent.TimeUnit

class DailyWorker(var ctx: Context, params: WorkerParameters) : Worker(ctx, params) {

    override fun doWork(): Result {
        val currentDate = Calendar.getInstance()
        val dueDate = Calendar.getInstance()


        Log.e("worker", "DailyWorker->doWork........")
        // 设置在大约 05:00:00 AM 执行
//        dueDate.set(Calendar.HOUR_OF_DAY, 5)
//        dueDate.set(Calendar.MINUTE, 0)
//        dueDate.set(Calendar.SECOND, 0)
//
//        if (dueDate.before(currentDate)) {
//            dueDate.add(Calendar.HOUR_OF_DAY, 24)
//        }
//
//        val timeDiff = (dueDate.timeInMillis - currentDate.timeInMillis)
//        val dailyWorkRequest = OneTimeWorkRequestBuilder<DailyWorker>()
//            .setInitialDelay(timeDiff, TimeUnit.MILLISECONDS)
//            .addTag("TAG_OUTPUT")
//            .build()
//
//        WorkManager.getInstance(applicationContext)
//            .enqueue(dailyWorkRequest)

        return Result.success()
    }

}